import { Match } from "@heroiclabs/nakama-js";
import { AudioType, ListenEventType, PanelType, PopupType } from "../../util/defineConfig";
import { nodeTouchStart } from "../../util/utilBase";
import View from "../../util/View";
import GameView from "../gameView";
import nakama from "../nakama";

const { ccclass, property } = cc._decorator;

@ccclass
export default class startPanel extends View {

    private view: any = {}
    private gameView: GameView = null

    init(gameView: GameView) {
        this.gameView = gameView
    }

    onLoad() {
        this.view = this.load_all_object(this.node, '')
        nodeTouchStart(this.view['but_play'], this.enterSelect.bind(this), this)
        nodeTouchStart(this.view['but_info'], this.showInfoPanel.bind(this), this)
    }

    private async enterSelect() {
        this.emit(ListenEventType.PLAY_EFFECT, AudioType.press_button)

        let session = nakama.authenticate(null, null) // todo 测试用的
        if (session)
            this.gameView.loadPanel(PanelType.SELECTPANEL)
    }
    public showInfoPanel() {
        this.emit(ListenEventType.PLAY_EFFECT, AudioType.press_button)
        this.show_ui_at(this.node, PanelType.POPUPPANEL, this, false, null, PopupType.info)
    }
}
